<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8>
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
</head>

<body>
    <div>03-数组的乱序输出</div>
    <script>
        // var arr = [1,2,3,4,5]
        // for(var i =0;i<arr.length;i++){
        //     const randomIndex = Math.round(Math.random()*(arr.length-1-i))+i;
        //     [arr[i],arr[randomIndex]] = [arr[randomIndex],arr[i]]
        // }
        // console.log(arr)

        var arr = [1,2,3,4,5]
        for(var i =0;i<arr.length;i++){
            const randomIndex = Math.round(Math.random()*(arr.length-1));
            [arr[i],arr[randomIndex]] = [arr[randomIndex],arr[i]]
        }
        console.log(arr)
   </script>
</body>

</html>
<!-- Math.round 四舍五入的操作   random生成0-0.9999随机数 -->
